using System;
using System.Windows.Threading;

namespace ebcpatterns.wpf
{
    public class Synchronizer : ISynchronizer
    {
        private readonly Dispatcher dispatcher;

        public Synchronizer() {
            dispatcher = Dispatcher.CurrentDispatcher;
        }

        public void Process() {
            dispatcher.Invoke(new Action(() => Result()));
        }

        public event Action Result;
    }

    public class Synchronizer<T> : ISynchronizer<T>
    {
        private readonly Dispatcher dispatcher;

        public Synchronizer() {
            dispatcher = Dispatcher.CurrentDispatcher;
        }

        public void Process(T t) {
            dispatcher.Invoke(new Action(() => Result(t)));
        }

        public event Action<T> Result;
    }
}